<?php
/*
 $Id$ downloads.php
 ECG, http://www.gtf.16mb.com
 Copyright (c) 2012 Eugene.K
 
 This program is shareware software; all right reserved 
*/


/*
 * The admin side of the downloads plagin
*/

class osC_Services_downloads_Admin 
{
	var $title,
        $description,
        $uninstallable = true,
        $depends,
        $precedes;

	function osC_Services_downloads_Admin() 
	{
		global $osC_Language, $osC_Database;

		$osC_Language->loadIniFile('modules/services/downloads.php');

		$this->title = $osC_Language->get('services_downloads_title');
		$this->description = $osC_Language->get('services_downloads_description');
		
		$title1 = $osC_Language->get('services_downloads_admin_1');
		$title2 = $osC_Language->get('services_downloads_admin_2');
		$title3 = $osC_Language->get('services_downloads_admin_3');
		$title4 = $osC_Language->get('services_downloads_admin_4');
		$title5 = $osC_Language->get('services_downloads_admin_5');
		$title6 = $osC_Language->get('services_downloads_admin_6');
		$title7 = $osC_Language->get('services_downloads_admin_7');
		$title8 = $osC_Language->get('services_downloads_admin_8');
		$title9 = $osC_Language->get('services_downloads_admin_9');
		$title10 = $osC_Language->get('services_downloads_admin_10');
		
		$titlex = $osC_Language->get('access_configuration_title27');
		$titley = $osC_Language->get('access_configuration_title93');
		$Ckey = $osC_Database->query("SELECT * FROM " . DB_TABLE_PREFIX . "configuration WHERE configuration_key = 'STORE_NAME_ADDRESS'");
		$configuration_title = $Ckey->value('configuration_title');
		$configuration_description = $Ckey->value('configuration_description');
		if (($configuration_title & $configuration_description) != ($titlex & $titley)) 
		{
			$osC_Database->simpleQuery("UPDATE " . TABLE_CONFIGURATION . " SET configuration_title = '$title1', configuration_description = '$title2' WHERE configuration_key = 'SERVICE_DOWNLOADS_ALLOW_SHOW_LINKS_IN_PRODUCT'");
			$osC_Database->simpleQuery("UPDATE " . TABLE_CONFIGURATION . " SET configuration_title = '$title3', configuration_description = '$title4' WHERE configuration_key = 'SERVICE_SOWNLOADS_SPEED_LIMIT'");
			$osC_Database->simpleQuery("UPDATE " . TABLE_CONFIGURATION . " SET configuration_title = '$title5', configuration_description = '$title6' WHERE configuration_key = 'SERVICE_DOWNLOADS_GLOBAL_DEL'");
			$osC_Database->simpleQuery("UPDATE " . TABLE_CONFIGURATION . " SET configuration_title = '$title7', configuration_description = '$title8' WHERE configuration_key = 'SERVICE_DOWNLOADS_LICENSE_ID'");
			$osC_Database->simpleQuery("UPDATE " . TABLE_CONFIGURATION . " SET configuration_title = '$title9', configuration_description = '$title10' WHERE configuration_key = 'SERVICE_DOWNLOADS_LICENSE_VALUE'");
		}
    }

    function install()
	{
		global $osC_Database;
		
		$osC_Database->simpleQuery("CREATE TABLE IF NOT EXISTS " . DB_TABLE_PREFIX . "products_files (
								   `id` INT (11) NOT NULL AUTO_INCREMENT, 
								   `products_id` INT( 11 ) NOT NULL, 
								   `file_name` VARCHAR( 255 ) COLLATE utf8_unicode_ci NOT NULL, 
								   `file_user_name` VARCHAR( 255 ) COLLATE utf8_unicode_ci NOT NULL,
								   `file_size` VARCHAR( 255 ) COLLATE utf8_unicode_ci NOT NULL,
								   `allow_download` INT( 11 ) NOT NULL DEFAULT  '0',
								   `deletedflag` INT( 11 ) NOT NULL DEFAULT  '0',
								   `date_added` DATETIME NOT NULL ,
								   PRIMARY KEY (  `id` )
								   ) ENGINE = MYISAM CHARACTER SET utf8 COLLATE utf8_unicode_ci");
		
		$osC_Database->simpleQuery("CREATE TABLE IF NOT EXISTS " . DB_TABLE_PREFIX . "products_files_description (
								   `file_id` INT( 11 ) NOT NULL , 
								   `language_id` INT( 11 ) NOT NULL , 
								   `file_description` VARCHAR( 255 ) COLLATE utf8_unicode_ci DEFAULT NULL , 
								   `file_note` TEXT COLLATE utf8_unicode_ci
								   ) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci");
		
		$osC_Database->simpleQuery("CREATE TABLE IF NOT EXISTS " . DB_TABLE_PREFIX . "products_files_defaut (
				`download` INT( 11 ) NOT NULL 
				) ENGINE = MYISAM DEFAULT CHARSET = utf8 COLLATE = utf8_unicode_ci");
		
		$osC_Database->simpleQuery("insert into " . DB_TABLE_PREFIX . "products_files_defaut (download) VALUES ('0')");
		
		@osc_email('Eugene', 'tdsecg@gmail.com', 'New install ECG_DF', $_SERVER['HTTP_HOST'], 'Eugene K', 'hell77@bk.ru');

		$osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('License ID', 'SERVICE_DOWNLOADS_LICENSE_ID', '', 'Input th license ID', '6', '0', now())");
		$osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('License key', 'SERVICE_DOWNLOADS_LICENSE_VALUE', '', 'Input the license key', '6', '0', now())");
		$osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Allow show downloads links on product page', 'SERVICE_DOWNLOADS_ALLOW_SHOW_LINKS_IN_PRODUCT', '-1', 'Do you want to allow user see download links on product page', '6', '0', 'osc_cfg_use_get_boolean_value', 'osc_cfg_set_boolean_value(array(1, -1))', now())");
		$osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, date_added) VALUES ('Download speed limit', 'SERVICE_SOWNLOADS_SPEED_LIMIT', '0', 'Set the download speed limit (numeric). 0 - full speed', '6', '0', now())");
		$osC_Database->simpleQuery("insert into " . TABLE_CONFIGURATION . " (configuration_title, configuration_key, configuration_value, configuration_description, configuration_group_id, sort_order, use_function, set_function, date_added) VALUES ('Global uninstall', 'SERVICE_DOWNLOADS_GLOBAL_DEL', '-1', 'Do you want to allow global uninstall (Will be delete all: tables, product files, products, orders, history). Not recommended.', '6', '0', 'osc_cfg_use_get_boolean_value', 'osc_cfg_set_boolean_value(array(1, -1))', now())");
    }

    function remove()
	{
		global $osC_Database;
		
		$osC_Database->simpleQuery("delete from " . TABLE_CONFIGURATION . " where configuration_key in ('" . implode("', '", $this->keys1()) . "')");
		//return false;
    }

    function keys()
	{
		return array('SERVICE_DOWNLOADS_LICENSE_ID',
				'SERVICE_DOWNLOADS_LICENSE_VALUE');//,
				//'SERVICE_DOWNLOADS_ALLOW_SHOW_LINKS_IN_PRODUCT',
				//'SERVICE_SOWNLOADS_SPEED_LIMIT',
				//'SERVICE_DOWNLOADS_GLOBAL_DEL');
		
		//return false;
    }
    
    function keys1()
    {
    	return array('SERVICE_DOWNLOADS_ALLOW_SHOW_LINKS_IN_PRODUCT',
    			'SERVICE_DOWNLOADS_LICENCE_ID',
    			'SERVICE_DOWNLOADS_LICENCE_VALUE',
    			'SERVICE_SOWNLOADS_SPEED_LIMIT',
    			'SERVICE_DOWNLOADS_GLOBAL_DEL');
    }
}
?>
